package com.common.util;

import android.os.Handler;

public class UIHandler {

	private static final String TAG = "UIHandler";
	private static UIHandler mInstance = null;

	public static UIHandler getInstance(){

		//第一个if是不加锁判断是否有创建实例，lazy 实例化策略
		if(mInstance == null){

			synchronized (UIHandler.class){
				//这里加锁后再判断是避免线程1拿到锁后开始实例化,另一个线程2在等待锁，然后线程1实例完后线程2又实例化了一遍，加上if判断则不会又这个问题
				if(mInstance == null){
					mInstance =  new UIHandler();
				}
			}
		}
		return mInstance;
	}
	
	public void post(Handler h,Runnable  r){
		if(h==null || r==null){
			return;
		}
		h.post(r);
	}
	
	public void postDelay(Handler h,Runnable r,long delayMillis){
		if(h==null || r==null){
			return;
		}
		h.postDelayed(r, delayMillis);
	}
	
	public void remove(Handler h,Runnable r){
		if(h==null || r==null){
			return;
		}
		h.removeCallbacks(r);
	}

}
